package main

import (
	"flag"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/config"
	modelConfig "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/config"
	modelRecharge "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/recharge"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/slot_game"
	modelTenantChannel "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/tenant/channel"
	modelUser "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/user"
	modelUserChannel "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/user/channel"
	modelUserWash "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/userwash"
	modelWithdraw "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/schema/withdraw"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"
	"github.com/zeromicro/go-zero/core/conf"
	"gorm.io/driver/mysql"
	"gorm.io/gen"
	"gorm.io/gorm"
)

func main() {
	var c config.Config
	configFile := flag.String("f", "assets-rpc/etc/lxz.yaml", "the config file")
	conf.MustLoad(*configFile, &c)

	// Initialize a *gorm.DB instance
	mysqlConfig := mysql.Config{
		DSN:                           c.DataSource, // DSN data source name
		DefaultStringSize:             191,          // string 类型字段的默认长度
		DontSupportNullAsDefaultValue: false,
		SkipInitializeWithVersion:     false, // 根据版本自动配置
	}
	db, err := gorm.Open(mysql.New(mysqlConfig), &gorm.Config{})
	if err != nil {
		panic(err)
	}

	// Initialize the generator with configuration
	g := gen.NewGenerator(gen.Config{
		OutPath:       "assets-rpc/internal/dao/model/query", // output directory, default value is ./query
		Mode:          gen.WithDefaultQuery | gen.WithoutContext | gen.WithQueryInterface,
		FieldNullable: true,
	})

	// Use the above `*gorm.DB` instance to initialize the generator,
	// which is required to generate structs from db when using `GenerateModel/GenerateModelAs`
	g.UseDB(db)

	// Generate default DAO interface for those specified structs
	g.ApplyBasic(
		slot_game.SlotGame{},
		slot_game.SlotHistory{},
		modelConfig.ConfigBank{},
		modelConfig.ConfigInoutType{},
		modelRecharge.RechargeChannel{},
		modelRecharge.RechargeOrder{},
		modelRecharge.RechargeType{},
		modelRecharge.RechargeVip{},
		modelTenantChannel.TenantChannelBank{},
		modelTenantChannel.TenantChannelBankAgent{},
		modelTenantChannel.TenantChannelBankAgentWithdraw{},
		modelTenantChannel.TenantChannelKbzpay{},
		modelTenantChannel.TenantChannelQrBank{},
		modelTenantChannel.TenantChannelUpi{},
		modelTenantChannel.TenantChannelUsdt{},
		modelTenantChannel.TenantChannelWavepay{},
		modelUserChannel.UserChannelBank{},
		modelUserChannel.UserChannelEwallet{},
		modelUserChannel.UserChannelLocalEwallet{},
		modelUserChannel.UserChannelPix{},
		modelUserChannel.UserChannelUsdt{},
		modelUser.UserPartnerReward{},
		modelUser.UserWallet{},
		modelUser.UserWalletLog{},
		modelWithdraw.WithdrawOrder{},
		modelWithdraw.WithdrawType{},
		modelWithdraw.WithdrawChannel{},
		modelUserWash.UserWash{},
		modelUserWash.UserWashBet{},
		rpc.UserAuth{},
		rpc.VirtualDic{},
	)

	// Execute the generator
	g.Execute()

	// // 创建数据库表
	SlotGame := &slot_game.SlotGame{}
	err = db.Table(SlotGame.TableName()).Set("gorm:table_options", "COMMENT='玩家游戏数据'").AutoMigrate(SlotGame)
	if err != nil {
		panic(err)
	}
	SlotHistory := &slot_game.SlotHistory{}
	err = db.Table(SlotHistory.TableName()).Set("gorm:table_options", "COMMENT='玩家游戏数据历史'").AutoMigrate(SlotHistory)
	if err != nil {
		panic(err)
	}
	// //// ---------------------- withdraw -------------------
	// err = db.Set("gorm:table_options", "COMMENT='币类型'").AutoMigrate(&rpc.VirtualDic{})

	// err = db.Set("gorm:table_options", "COMMENT='实名认证表'").AutoMigrate(&rpc.UserAuth{})
	// err = db.Set("gorm:table_options", "COMMENT='提现订单表'").AutoMigrate(&modelWithdraw.WithdrawOrder{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='提现类型表'").AutoMigrate(&modelWithdraw.WithdrawType{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='提现代付通道表'").AutoMigrate(&modelWithdraw.WithdrawChannel{})
	// if err != nil {
	// 	panic(err)
	// }
	// // // ---------------------- config -------------------
	// err = db.Set("gorm:table_options", "COMMENT='银行字典表'").AutoMigrate(&modelConfig.ConfigBank{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='余额变动类型表'").AutoMigrate(&modelConfig.ConfigInoutType{})
	// if err != nil {
	// 	panic(err)
	// }
	// // ---------------------- recharge -------------------
	// err = db.Set("gorm:table_options", "COMMENT='充值通道表'").AutoMigrate(&modelRecharge.RechargeChannel{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='充值订单表'").AutoMigrate(&modelRecharge.RechargeOrder{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='充值类型表'").AutoMigrate(&modelRecharge.RechargeType{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='vip充值配置表'").AutoMigrate(&modelRecharge.RechargeVip{})
	// if err != nil {
	// 	panic(err)
	// }
	// // // ---------------------- tenant channel -------------------
	// err = db.Set("gorm:table_options", "COMMENT='商户通道表【bank】'").AutoMigrate(&modelTenantChannel.TenantChannelBank{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='商户通道表【bank_agent】'").AutoMigrate(&modelTenantChannel.TenantChannelBankAgent{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='代付三方银行表【bank_agent_withdraw】'").AutoMigrate(&modelTenantChannel.TenantChannelBankAgent{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='商户通道表【kbzpay】'").AutoMigrate(&modelTenantChannel.TenantChannelKbzpay{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='商户通道表【qr_bank】'").AutoMigrate(&modelTenantChannel.TenantChannelQrBank{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='商户通道表【upi】'").AutoMigrate(&modelTenantChannel.TenantChannelUpi{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='商户通道表【usdt】'").AutoMigrate(&modelTenantChannel.TenantChannelUsdt{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='商户通道表【wavepay】'").AutoMigrate(&modelTenantChannel.TenantChannelWavepay{})
	// if err != nil {
	// 	panic(err)
	// }
	// // // ---------------------- user channel -------------------
	// err = db.Set("gorm:table_options", "COMMENT='用户通道表【bank】'").AutoMigrate(&modelUserChannel.UserChannelBank{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='用户通道表【ewallet】'").AutoMigrate(&modelUserChannel.UserChannelEwallet{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='用户通道表【local_ewallet】'").AutoMigrate(&modelUserChannel.UserChannelLocalEwallet{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='用户通道表【pix】'").AutoMigrate(&modelUserChannel.UserChannelPix{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='用户通道表【usdt】'").AutoMigrate(&modelUserChannel.UserChannelUsdt{})
	// if err != nil {
	// 	panic(err)
	// }
	// // // ---------------------- user -------------------
	// err = db.Set("gorm:table_options", "COMMENT='用户合伙人奖励表'").AutoMigrate(&modelUser.UserPartnerReward{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='用户钱包表'").AutoMigrate(&modelUser.UserWallet{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='用户钱包变更日志表'").AutoMigrate(&modelUser.UserWalletLog{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='用户洗码表'").AutoMigrate(&modelUserWash.UserWash{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='用户洗码投注表'").AutoMigrate(&modelUserWash.UserWashBet{})
	// if err != nil {
	// 	panic(err)
	// }
	// err = db.Set("gorm:table_options", "COMMENT='用户洗码描述表'").AutoMigrate(&modelUserWash.UserWashDesc{})
	// if err != nil {
	// 	panic(err)
	// }
}

// AddTag adds a tag to a field of a struct
